import module namespace page="http://sendmeafilter.com/common/page" at "../common/page.xqy";

declare boundary-space preserve;
declare option xdmp:mapping "false";

declare variable $file := xdmp:get-request-field('file');
declare variable $useCK := xdmp:get-request-field('nock','false') = 'false';
declare variable $doc := fn:doc($file)/node();
declare variable $fixdoc := if($doc) then xdmp:quote($doc/node()) else '<p>Enter info here</p>';

page:page (
	(
		page:meta('title', 'Edit Configuration - SendMeAFilter.com'),
		page:meta('backoffice'),
		if($useCK) then page:meta('ckeditor') else ()
	),

	<div class="wrapper">
		<div class="caption">
			<div float="right">
				<h3>Edit {xdmp:get-request-field('file')}</h3>
		
			</div>
			<br/>
			<div>
				<div>
					<form name="theForm" method="post" onSubmit="return validateForm(this);" action="editconfigpost" enctype="multipart/form-data">
						<textarea class="editConfigArea" id="xml" name="xml">{$fixdoc}</textarea>
						<span id="xmlError" class="error"/>
						{ 
							if(fn:not($useCK)) then () else 
								<script type="text/javascript">
									CKEDITOR.replace( 'xml' ,
								    {{
								        toolbar : 'Full',
								        // uiColor : '#9AB8F3'
								    }});
								</script>
						}
						<br/>
						<input class="button-style" id="inputButton" type="submit" value="Submit"/>
						&nbsp; &nbsp; 
						<input class="button-style" id="inputButton" type="submit" value="Cancel"/>
						<input name="file" type="hidden" value="{xdmp:get-request-field('file')}"/>
					</form>
				</div>
			</div>
		</div>
	</div>
)
	
